package com.sys.orders.back.controller;

import static org.hamcrest.CoreMatchers.instanceOf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sys.common.controller.BaseController;
import com.sys.common.pojo.ApiResponse;
import com.sys.common.util.ConstatFinalUtil;
import com.sys.common.util.PageInfoUtil;
import com.sys.orders.pojo.AOrdersComment;
import com.sys.orders.service.IOrdersDbService;

@Controller
@RequestMapping("/back/ordersComment")
public class ordersCommentBackController extends BaseController
{
	@Autowired
	private IOrdersDbService ordersDbService;

	/**
	 * 订单评论列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/ordersCommentList")
	public String ordersCommentList(HttpServletRequest request, HttpServletResponse response)
	{
		ConstatFinalUtil.SYS_LOGGER.info("====ordersCommentList======");
		/* 生成分页对象 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 生成查询条件 */
		Map<String, Object> condMap = this.proccedSearch(request);

		ApiResponse<AOrdersComment> ordersCommentList = this.ordersDbService
				.findCondListAOrdersCommentService(pageInfoUtil, condMap);
		List<AOrdersComment> dataListJava = ordersCommentList.getDataListJava();

		request.setAttribute("list", dataListJava);
		request.setAttribute("pageInfoUtil", pageInfoUtil);

		return "/back/order/ordersCommentList";
	}

	/**
	 * 订单评论插入
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/ordersCommentInsert")
	public String ordersCommentInsertt(HttpServletRequest request, HttpServletResponse response)
	{
		ConstatFinalUtil.SYS_LOGGER.info("=======ordersCommentInsert========");
		return "/back/order/ordersCommentInsert";
	}

	/**
	 * 订单评论插入提交
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/ordersCommentInsertSubmit")
	public String ordersCommentInsertSubmit(HttpServletRequest request, HttpServletResponse response)
	{
		ConstatFinalUtil.SYS_LOGGER.info("=======ordersCommentInsertSubmit========");
		/* 接收参数 */
		String orderId = request.getParameter("orderId");
		String commentContent = request.getParameter("commentContent");
		String stars = request.getParameter("stars");
		String status = request.getParameter("status");

		/* 创建对象 */
		AOrdersComment ordersComment = new AOrdersComment();

		ordersComment.setOrderID(Integer.valueOf(orderId));
		ordersComment.setCommentContent(commentContent);
		ordersComment.setStars(Integer.valueOf(stars));
		ordersComment.setStars(Byte.valueOf(status));

		ApiResponse<Object> apiResponse = this.ordersDbService.saveOneAOrdersCommentService(ordersComment);

		return apiResponse.toJSON().toJSONString();
	}

	/**
	 * 订单评论更新
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/ordersCommentUpdate")
	public String ordersCommentUpdate(HttpServletRequest request, HttpServletResponse response)
	{
		ConstatFinalUtil.SYS_LOGGER.info("=======ordersCommentUpdate========");

		String id = request.getParameter("id");

		Map<String, Object> condMap = new HashMap<String, Object>();

		condMap.put("id", Integer.valueOf(id));
		ApiResponse<AOrdersComment> comment = this.ordersDbService.findOneAOrdersCommentService(condMap);

		AOrdersComment ordersComment = comment.getDataOneJava();
		
		request.setAttribute("ordersComment", ordersComment);

		return "/back/order/ordersCommentUpdate";
	}

	/**
	 * 订单评论更新提交
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/ordersCommentUpdateSubmit")
	public String ordersCommentUpdateSubmit(HttpServletRequest request, HttpServletResponse response)
	{
		ConstatFinalUtil.SYS_LOGGER.info("=======ordersCommentUpdateSubmit========");

		String id = request.getParameter("id");

		Map<String, Object> condMap = new HashMap<String, Object>();

		condMap.put("id", Integer.valueOf(id));
		ApiResponse<AOrdersComment> comment = this.ordersDbService.findOneAOrdersCommentService(condMap);

		AOrdersComment ordersComment = comment.getDataOneJava();

		/* 接收参数 */
		String orderId = request.getParameter("orderId");
		String commentContent = request.getParameter("commentContent");
		String stars = request.getParameter("stars");
		String status = request.getParameter("status");

		ordersComment.setOrderID(Integer.valueOf(orderId));
		ordersComment.setCommentContent(commentContent);
		ordersComment.setStars(Integer.valueOf(stars));
		ordersComment.setStars(Byte.valueOf(status));

		ApiResponse<Object> apiResponse = this.ordersDbService.updateOneAOrdersCommentService(ordersComment);
		ConstatFinalUtil.SYS_LOGGER.info(apiResponse.toJSON().toJSONString());

		return apiResponse.toJSON().toJSONString();
	}

}
